﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.SessionState;
using System.Web.Routing;
using System.Text;

namespace DreamBox.Net.Web.Http
{
    public class HttpHandler : IHttpHandler, IRequiresSessionState
    {

        public RequestContext RequestContext
        {
            get;
            set;
        }
        public HttpHandler(RequestContext RequestContext) 
        {

            this.RequestContext = RequestContext;
        }
        public void ProcessRequest(HttpContext HttpContext)
        {
            //权限处理
            bool result= HttpInvoke.Competence(RequestContext);
            //启动请求处理
            if (result)
            {
                HttpInvoke.Init(RequestContext);
            }
            else
            {
                if (RequestContext.HttpContext.Request.Headers["X-Requested-With"] != null && RequestContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
                {
                    HttpContext.Response.Write("competence");
                }
                else
                {
                    RequestContext.HttpContext.Response.Redirect("/message?msg=您所在的用户组没有该项权限&url=&display=");
                }
            }
        }
        public bool IsReusable
        {
            get { return false; }
        }
    }
}
